package com.java.mywxmp.controller;

import java.util.Arrays;
import java.util.Map;

import com.java.mywxmp.utils.PageUtils;
import com.java.mywxmp.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.java.mywxmp.entity.User;
import com.java.mywxmp.service.UserService;


/**
 * 用户表
 *
 * @author jl
 * @since 2020-08-25 14:53:40
 */
@RestController
@RequestMapping("wx/user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 带条件分页查询user
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = userService.queryPage(params);

        return R.ok(page);
    }


    /**
     * 根据主键查询user
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id) {
        User user = userService.getById(id);

        return R.ok(user);
    }

    /**
     * 新增user
     */
    @PostMapping("/save")
    public R save(@RequestBody User user) {
        userService.save(user);

        return R.ok();
    }

    /**
     * 修改user
     */
    @PutMapping("/update")
    public R update(@RequestBody User user) {
        userService.updateById(user);

        return R.ok();
    }

    /**
     * 删除user
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody Integer[] ids) {
        userService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
